home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / comm / byepc300.zip / BYESHELL.ZIP / SHELL.C < prev    next >
Text File  |  1987-10-24  |  21KB  |  1,030 lines

  1. /*
  2. **  File:    <shell.c>
  3. **
  4. **  Purpose:    Security Command Line Processor for BYE-PC
  5. **
  6. **  Author:    R.E. Starr, Jr.
  7. **
  8. **  Date:    12/31/86
  9. **
  10. **  Revisons:    1.04 - (03/28/87)  Modified caller status word to
  11. **            allow up to 16 disk drives in system.
  12. **
  13. **        1.05 - (03/30/87)  Modified to check for precsence
  14. **            of BYE-PC before calling any external functions.
  15. **            This allows SHELL to function without BYE-PC.
  16. **
  17. **        1.06 - (03/31/87)  Added 'getdrive()' to read the
  18. **            current default drive instead of keeping up
  19. **            with it in a storage location.
  20. **
  21. **        1.07 - (04/05/87)  Added redirection checking
  22. **
  23. **        1.08 - (05/01/87)  Added command line options for
  24. **            debugging and status level settings.
  25. **
  26. **        1.09 - (05/01/87)  Added missing drive table to map
  27. **            out invalid/non-supported drives.
  28. **
  29. **        1.10 - (05/08/87)  Modified for byexface ver 2.00
  30. */
  31.  
  32. #include <stdio.h>    /* std Microsoft C headers */
  33. #include <stdlib.h>
  34. #include <conio.h>
  35. #include <ctype.h>
  36. #include <process.h>
  37. #include <signal.h>
  38. #include <string.h>
  39. #include <direct.h>
  40. #include <dos.h>
  41. #include <time.h>
  42. #include "byexface.h"    /* BYE-PC interface functions */
  43.  
  44.  
  45.     /* SHELL configuration section */
  46.  
  47. /* #define PCURS    * define for dos cursor with path name */
  48. #define MAX_DRV 'C'    /* max drives in system, 16 max. (A-P) */
  49.  
  50. #define VER    1    /* SHELL Version# */
  51. #define REV    10    /* SHELL Revision# */
  52.  
  53. #define BYE_VER 3    /* minimum BYE-PC version# required */
  54. #define BYE_REV 0    /* minimum BYE-PC revision# required */
  55.  
  56. #define BIT_0    0x0001
  57. #define BIT_1    0x0002
  58. #define BIT_2    0x0004
  59. #define BIT_3    0x0008
  60. #define BIT_4    0x0010
  61. #define BIT_5    0x0020
  62. #define BIT_6    0x0040
  63. #define BIT_7    0x0080
  64.  
  65.  
  66.     /* function declarations */
  67.  
  68. void commands(), intrinsic(), extrinsic();
  69. void pset_parms(), pset_flags(), pflags_error();
  70.  
  71. int binary(), break_handler();
  72. int drv_cmd(), null_cmd(), type_cmd(), time_cmd();
  73. int dos_cmd(), exit_cmd(), cd_cmd(), format_cmd(), dir_cmd();
  74.  
  75.  
  76.     /* static data declarations */
  77.  
  78. static char Com_spec[64];        /* file spec of COMMAND.COM */
  79. static char Errors = 0;         /* # of persistant Errors */
  80. static char Bye_flg = 1;        /* BYE-PC loaded flag */
  81. static char Debug = 0;            /* BYE-PC not loaded mode */
  82. static unsigned Cstat = 0;        /* caller status level */
  83. static unsigned Csw = 0;        /* debug mode status flags */
  84.  
  85.  
  86.    /* ----------------------- NOTE ----------------------------*/
  87.    /* The following table is searched using a binary search    */
  88.    /* and all strings must be in assending alphabetical order. */
  89.    /* ---------------------------------------------------------*/
  90.  
  91. #define PCMDS  (sizeof(cmdpri) / sizeof(struct key))
  92. #define RPATHS (sizeof(rpath) / sizeof(struct paths))
  93. #define IPATHS (sizeof(ipath) / sizeof(struct paths))
  94. #define MDRIVE (sizeof(mdrvs))
  95.  
  96.  
  97.     /* missing system drives */
  98.  
  99. char mdrvs[] =            /* missing drive map */
  100.     {
  101.     'D',            /* drive D: not supported */
  102.     'E',            /* drive E: not supported */
  103.     };
  104.  
  105.     /* intrinsic command table functions */
  106.  
  107. struct key
  108.     {
  109.     char *keyword;        /* pointer to intrinsic key words */
  110.     int (*key_fxn)();        /* pointer to intrinsic functions */
  111.     };
  112. struct key cmdpri[] =        /* primary command set */
  113.     {
  114.     "ASSIGN", null_cmd,
  115.     "ATTRIB", null_cmd,
  116.     "BACKUP", null_cmd,
  117.     "BASIC", null_cmd,
  118.     "BASICA", null_cmd,
  119.     "BREAK", null_cmd,
  120.     "CD", cd_cmd,
  121.     "CHDIR", cd_cmd,
  122.     "COMMAND", null_cmd,
  123.     "COMP", null_cmd,
  124.     "COPY", null_cmd,
  125.     "CTTY", null_cmd,
  126.     "DATE", time_cmd,
  127.     "DEL", null_cmd,
  128.     "DIR", dir_cmd,
  129.     "DISKCOMP", null_cmd,
  130.     "DISKCOPY", null_cmd,
  131.     "DOS", dos_cmd,
  132.     "ERASE", null_cmd,
  133.     "EXE2BIN", null_cmd,
  134.     "EXIT", exit_cmd,
  135.     "FDISK", null_cmd,
  136.     "FORMAT", format_cmd,
  137.     "GRAFTABL", null_cmd,
  138.     "GRAPHICS", null_cmd,
  139.     "JOIN", null_cmd,
  140.     "KEYBFR", null_cmd,
  141.     "KEYBGR", null_cmd,
  142.     "KEYBIT", null_cmd,
  143.     "KEYBSP", null_cmd,
  144.     "KEYBUK", null_cmd,
  145.     "LABEL", null_cmd,
  146.     "MD", null_cmd,
  147.     "MKDIR", null_cmd,
  148.     "MODE", null_cmd,
  149.     "PATH", null_cmd,
  150.     "PRINT", null_cmd,
  151.     "PROMPT", null_cmd,
  152.     "RD", null_cmd,
  153.     "RECOVER", null_cmd,
  154.     "REN", null_cmd,
  155.     "RESTORE", null_cmd,
  156.     "RMDIR", null_cmd,
  157.     "SELECT", null_cmd,
  158.     "SET", null_cmd,
  159.     "SHARE", null_cmd,
  160.     "SHELL", null_cmd,
  161.     "SYS", null_cmd,
  162.     "TIME", time_cmd,
  163.     "TREE", null_cmd,
  164.     "TYPE", type_cmd,
  165.     "VER", null_cmd,
  166.     "VERIFY", null_cmd,
  167.     "VOL", null_cmd,
  168.     };
  169.  
  170.     /* invalid and restricted DOS paths */
  171.  
  172. struct paths
  173.     {
  174.     char *path;         /* pointer to paths */
  175.     };
  176.  
  177. struct paths ipath[] =        /* illegal DOS path names */
  178.     {
  179.     "SYSTEM",
  180.     "DOS",
  181.     "XBBS",
  182.     };
  183.  
  184. struct paths rpath[] =        /* restriced DOS path names */
  185.     {
  186.     "UPLOADS",
  187.     "PRIVATE",
  188.     };
  189.  
  190.  
  191. /*
  192. **  Function:    void main()
  193. **
  194. **  Paramters:    int argc;
  195. **        char *argv[];
  196. **
  197. **  Purpose:    Main shell calling routine
  198. **
  199. **  Return:    void
  200. */
  201.  
  202. main(argc, argv)
  203.  
  204.  int argc;
  205.  char *argv[];
  206.     {
  207.     int rtn, n;
  208.     char *ptr;
  209.     char inp_buf[80];
  210.     char tmp_buf[80];
  211.     extern struct cmdpri;
  212.  
  213.     Debug = 0;
  214.     Csw = 0;
  215.     pset_parms(argc, argv);    /* check cmd line line flags */
  216.  
  217.     if (signal(SIGINT, break_handler) == (int(*)()) -1)
  218.     printf("\nWARNING: Can't disable CTRL-BREAK interrupt!\n");
  219.  
  220.     if (rtn = _bye_check(BYE_VER, BYE_REV))
  221.     {
  222.     if (rtn == 1)
  223.         {
  224.         Bye_flg = 0;
  225.         if (Debug)
  226.         printf("\nWARNING: BYE-PC not loaded - 'EXIT' to quit SHELL\n");   /* internal error */
  227.         else
  228.         exit(1);
  229.         }
  230.     else
  231.         {
  232.         printf("\nSHELL ERROR: BYE-PC ");    /* internal error */
  233.         switch(rtn)
  234.         {
  235.         case 2:
  236.             printf("loaded is the wrong Version!\n");
  237.             break;
  238.         case 3:
  239.             printf("loaded is the wrong Revision!\n");
  240.             break;
  241.         default:
  242.             printf("returned invalid error code!\n");
  243.             break;
  244.         }
  245.         exit(1);
  246.         }
  247.     }
  248.     get_comspec(Com_spec);        /* get file spec for COMMAND.COM */
  249.     if (Bye_flg)
  250.     {
  251.     _bye_setbreak(CTRL_BRK);    /* now enable ctrl-breaks  */
  252.     Cstat = _bye_getcsw();        /* get callers status */
  253.     }
  254.     else
  255.     Cstat = (Csw != NULL) ? Csw : 0xff00;
  256.                     /* since we trap them here */
  257.     while(1)
  258.     {
  259.     if (Bye_flg)
  260.         Cstat = _bye_getcsw();    /* reset callers status */
  261.     if (!get_cmd(inp_buf, 63))    /* get a line from stdin */
  262.         continue;
  263.     ptr = strupr(inp_buf);        /* make string upper case */
  264.     while(*ptr == ' ')        /* skip over leading spaces */
  265.         *ptr++;
  266.     strcpy(inp_buf, ptr);        /* remove all leading spaces */
  267.     strcpy(tmp_buf, ptr);        /* make a copy of input str  */
  268.     if (tmp_buf[0] == '\0')     /* loop if no data entered   */
  269.         continue;
  270.     printf("\n");
  271.     if (tmp_buf[1] == ':')
  272.         {
  273.         if (tmp_buf[2] == '\0')
  274.         {
  275.         drv_cmd(tmp_buf);
  276.         continue;
  277.         }
  278.         else
  279.         {
  280.         if (bad_drive(inp_buf)) /* check drive first */
  281.             continue;
  282.         *ptr++;         /* execute on another drive */
  283.         *ptr++;
  284.         strcpy(tmp_buf, ptr);
  285.         }
  286.         }
  287.     if ((ptr = strchr(tmp_buf, ' ')) != NULL)
  288.         *ptr = '\0';
  289.     if ((n = binary(tmp_buf, cmdpri, PCMDS)) != EOF)
  290.         (*cmdpri[n].key_fxn)(inp_buf);  /* do function internally */
  291.     else
  292.         extrinsic(inp_buf);         /* DOS system call.     */
  293.     }
  294.     }
  295.  
  296.  
  297. /*
  298. **  Function:    void extrinsic(input_string)
  299. **
  300. **  Parms:    char *input_string
  301. **
  302. **  Purpose:    Passes the string to the system to execute as
  303. **        a system command it possible.
  304. **
  305. **  Return:    void
  306. */
  307.  
  308. void extrinsic(input_string)
  309.  
  310.  char *input_string;
  311.     {
  312.     int status;
  313.  
  314.     if (!(*input_string))        /* any command to try? */
  315.     return;             /*    no, reuturn.       */
  316.     if (bad_path(input_string, 1))  /* check for bad paths */
  317.     return;
  318.     Errors = 0;             /* reset persistant error ctr */
  319.     status = system(input_string);
  320.     if (status)
  321.     printf("\n[EXEC of COMMAND.COM failed!]\n");
  322.     }
  323.  
  324.  
  325. /*
  326. **  Function:    void prompt()
  327. **
  328. **  Parms:    void
  329. **
  330. **  Purpose:    Shows the cursor prompt
  331. **
  332. **  Return:    void
  333. */
  334.  
  335. prompt()
  336.  {
  337. #ifdef PCURS
  338.  char pathbuf[51];
  339.  
  340.  if (getc